﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

/// <summary>
/// Summary description for datMenu
/// </summary>
public class datMenu
{
	public datMenu()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    SqlCommand cmd;
    SqlDataReader dr;
    public bool checkQuyenVaoTrang(int userid, int trang)
    {
        string constr = System.Configuration.ConfigurationManager.ConnectionStrings["conStr3"].ConnectionString;
        SqlConnection sqlConnection = new SqlConnection(constr);
        sqlConnection.Open();
        cmd = new SqlCommand("sp_MenuCheckQuyenVaoTrang", sqlConnection);
        cmd.CommandType = CommandType.StoredProcedure;
        SqlParameter[] sqla = new SqlParameter[2];
        sqla[0] = new SqlParameter("userid", DbType.String);
        sqla[1] = new SqlParameter("menuid", DbType.String);


        sqla[0].Value = userid;
        sqla[1].Value = trang;


        cmd.Parameters.AddRange(sqla);

        dr = cmd.ExecuteReader();
        if (dr.Read())
        {
            dr.Close();
            sqlConnection.Close();
            return true;
        }
        dr.Close();
        sqlConnection.Close();
        return false;
    }

    public List<entMenu> getMenuCha(int userid)
    {
        string constr = System.Configuration.ConfigurationManager.ConnectionStrings["conStr3"].ConnectionString;
        SqlConnection sqlConnection = new SqlConnection(constr);
        sqlConnection.Open();
        cmd = new SqlCommand("sp_MenuGetMenuChaByUserId", sqlConnection);
        cmd.CommandType = CommandType.StoredProcedure;
        SqlParameter[] sqla = new SqlParameter[1];
        sqla[0] = new SqlParameter("userid", DbType.String);
        sqla[0].Value = userid;
       

        cmd.Parameters.AddRange(sqla);

        dr = cmd.ExecuteReader();
        entMenu entM;
        List<entMenu> lst = new List<entMenu>();
        while (dr.Read())
        {
            entM = new entMenu();
            entM.path = dr["path"].ToString();
            entM.MenuChaId = int.Parse(dr["menuchaid"].ToString());
            entM.TenMenu = dr["menuname"].ToString();
            entM.MenuId = int.Parse(dr["menuid"].ToString());
            entM.Icon = dr["icon"].ToString();
            lst.Add(entM);
        }
        dr.Close();
        sqlConnection.Close();
        return lst;
    }
    public List<entMenu> getMenuCon(int userid, int menuchaid)
    {
        string constr = System.Configuration.ConfigurationManager.ConnectionStrings["conStr3"].ConnectionString;
        SqlConnection sqlConnection = new SqlConnection(constr);
        sqlConnection.Open();
        cmd = new SqlCommand("sp_MenuGetMenuConByUserIdMenuChaId", sqlConnection);
        cmd.CommandType = CommandType.StoredProcedure;
        SqlParameter[] sqla = new SqlParameter[2];
        sqla[0] = new SqlParameter("userid", DbType.Int32);
        sqla[1] = new SqlParameter("Menuchaid", DbType.Int32);
        sqla[0].Value = userid;
        sqla[1].Value = menuchaid;


        cmd.Parameters.AddRange(sqla);

        dr = cmd.ExecuteReader();
        entMenu entM;
        List<entMenu> lst = new List<entMenu>();
        while (dr.Read())
        {
            entM = new entMenu();
            entM.path = dr["path"].ToString();
            entM.MenuChaId = int.Parse(dr["menuchaid"].ToString());
            entM.TenMenu = dr["menuname"].ToString();
            lst.Add(entM);
        }
        dr.Close();
        sqlConnection.Close();
        return lst;
    }
}